﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Windows.Foundation;
using Windows.UI.Xaml.Media;

namespace BoolanElement
{
    public class BooShapesPoints
    {

        public static PointCollection CopyPointCollection(PointCollection ptCollection)
        {
            Point[] pt = new Point[ptCollection.Count];
            PointCollection pts = new PointCollection();
            ptCollection.CopyTo(pt, 0);
            for (int i = 0; i < ptCollection.Count; i++)
            {
                pts.Add(pt[i]);
            }

            return pts;
        }

        public static XElement SavePoints(PointCollection Points)
        {
            XElement points = new XElement("Points");

            for (int i = 0; i < Points.Count; i++)
            {
                int num = i + 1;
                XElement point = new XElement("Point" + num);

                point.SetAttributeValue("X", Points[i].X);
                point.SetAttributeValue("Y", Points[i].Y);

                points.Add(point);
            }

            return points;
        }

        public static PointCollection LoadPoints(IEnumerable<XElement> elements)
        {
            PointCollection pointCol = new PointCollection();

            foreach (var p in elements)
            {
                double x = Double.Parse(p.Attribute("X").Value.ToString());
                double y = Double.Parse(p.Attribute("Y").Value.ToString());

                Point point = new Point(x, y);
                pointCol.Add(point);
            }

            return pointCol;
        }

    }
}
